1 00:00:01,870 --> 00:00:02,630 Hey there. 2 00:00:02,650 --> 00:00:07,990 I have one last practice problem for you to solve before we move on to making games on roadblocks. 3 00:00:08,410 --> 00:00:09,970 Your task is this. 4 00:00:10,180 --> 00:00:14,660 I'd like you to create a function that takes a number argument using that number. 5 00:00:14,680 --> 00:00:17,260 I want you to check if it's divisible by three. 6 00:00:17,470 --> 00:00:19,990 If so, you'll print physx. 7 00:00:20,260 --> 00:00:24,490 If the number is divisible by five, then you'll print buzz. 8 00:00:24,580 --> 00:00:30,310 Otherwise, if the number is divisible by both three and five, you'll print physx Buzz. 9 00:00:30,760 --> 00:00:35,470 Please take a minute or two to solve this problem and I'll show you my solution next. 10 00:00:38,730 --> 00:00:42,390 Okay to solve this problem, I'll first create my function. 11 00:00:42,390 --> 00:00:44,040 Call it fizz buzz. 12 00:00:44,790 --> 00:00:46,860 And have a parameter named num. 13 00:00:47,910 --> 00:00:55,260 Next I'll create an if statement and first check if the num is divisible by both three and five using 14 00:00:55,260 --> 00:00:56,670 the modulus operator. 15 00:00:57,800 --> 00:01:03,110 I check if the return from this operation is zero, meaning that no remainder was left over and this 16 00:01:03,110 --> 00:01:05,600 number is divisible by three and five. 17 00:01:06,140 --> 00:01:11,450 I check this one first because the most complex conditions should be at the top of your if statements 18 00:01:11,690 --> 00:01:16,580 with conditions that reducing complexity to go further and further down your if statements. 19 00:01:16,970 --> 00:01:22,910 This is because if I had this complex condition at the end and pass a number like 15, it would never 20 00:01:22,910 --> 00:01:30,020 print fiz buzz because condition like num modulus three would evaluate to true and ignore all the rest. 21 00:01:30,620 --> 00:01:32,450 15 can also be divided by five. 22 00:01:32,450 --> 00:01:37,370 So if that was the first condition to be checked, it would evaluate the true and ignore the other conditions. 23 00:01:37,910 --> 00:01:43,220 So if I have my complex condition at the bottom, I'll never be able to reach it due to the less complex 24 00:01:43,220 --> 00:01:44,360 conditions above it. 25 00:01:45,450 --> 00:01:49,830 Next, I'll do live and check to see if the num is divisible by three. 26 00:01:51,550 --> 00:01:53,290 If so, I'll print fiz. 27 00:01:53,860 --> 00:01:57,460 And lastly, I'll check for the number is divisible by five. 28 00:01:58,550 --> 00:02:00,890 And if so, I'll print buzz. 29 00:02:02,680 --> 00:02:08,620 Now I can call this function and pass the number like 15 and it should print fizz buzz. 30 00:02:08,770 --> 00:02:10,060 Let's run the script. 31 00:02:11,070 --> 00:02:11,880 And perfect. 32 00:02:11,880 --> 00:02:13,170 We get fizz buzz. 33 00:02:14,170 --> 00:02:15,580 Now in the test. 34 00:02:16,520 --> 00:02:20,510 Pass five instead of my function and then run my game again. 35 00:02:20,510 --> 00:02:22,100 And it should print buzz. 36 00:02:25,770 --> 00:02:26,300 Okay. 37 00:02:26,310 --> 00:02:28,800 The last number I'll pass is three. 38 00:02:29,510 --> 00:02:31,340 And it should print fiz. 39 00:02:32,980 --> 00:02:33,760 Excellent.